﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

using ADO_QLNS.DTO;

namespace ADO_QLNS
{
    public abstract class QLNS_ADO
    {
        private ADOHelper _Helper = new ADOHelper(new Utils.SqlDataProvider());

        public void Insert(ITransferObject dtoInsert)
        {
            _Helper.Connect();
            {
                _Helper.exeNonQuery(OnInsert(dtoInsert));
            }
            _Helper.Disconnect();
        }

        public void Update(ITransferObject dtoUpdate)
        {
            _Helper.Connect();
            {
                _Helper.exeNonQuery(OnUpdate(dtoUpdate));
            }
            _Helper.Disconnect();
        }

        public void Delete(ITransferObject dtoDelete)
        {
            _Helper.Connect();
            {
                _Helper.exeNonQuery(OnDelete(dtoDelete));
            }
            _Helper.Disconnect();
        }

        //public List<ITransferObject> Search(int id)
        //{
        //    _Helper.Connect();
        //    { }
        //    _Helper.Disconnect();
        //}

        protected ArrayList ConvertDataSetToArrayList(DataSet dataset)
        {
            ArrayList arrlist = new ArrayList();
            DataTable dt = dataset.Tables[0];
            int i, n = dt.Rows.Count;
            for (i = 0; i < n; ++i)
            {
                object obj = GetDataFromDataRow(dt, i);
                arrlist.Add(obj);
            }

            return arrlist;
        }

        protected abstract string OnInsert(ITransferObject dto);
        protected abstract string OnUpdate(ITransferObject dto);
        protected abstract string OnDelete(ITransferObject dto);
        protected abstract object GetDataFromDataRow(DataTable dt, int i);
    }
}
